import './index.css'

import React, {Component} from 'react';
import { Switch, Route, Redirect} from 'react-router-dom'
import { Layout, Divider } from 'antd';
import PubSub from "pubsub-js";

import Top_Header from "../../components/header";
import Top_Menu from "../../components/menu";
import Data from "../../pages/Data/data";
import Start from "../Start/start";
import Person from "../Person/person"
import Use from "../Use/Use";
import memoryUtils from "../../utils/memoryUtils";


class Index extends Component {
  state = {
    isLogin: false
  }

  componentDidMount() {
    PubSub.subscribe('sendLoginParam', (name, flag) => {
      this.setState({
        isLogin: flag
      })
    })
    PubSub.subscribe('sendLogoutParam', (name, flag) => {
      this.setState({
        isLogin: flag
      })
    })
  }

  render() {
    // 如果是没有登录的状态，则自动跳转到登录页面
    const user = memoryUtils.user
    if (!user.id) {
      return <Redirect to="/login"/>
    }

    return (
      <Layout style={{ height:'100%' }}>
        {/*顶部*/}
        <Top_Header />
        {/*导航菜单*/}
        <Top_Menu />
        <Divider style={{ width:'100%', margin:'0' }} />
        <Layout style={{ background:'#29282c' }}>
          <Switch>
            <Route path="/index/data" component={Data}/>
            <Route path="/index/person" component={Person}/>
            <Route path="/index/use" component={Use} />
            <Route path="/index/start" component={Start} />
            <Redirect to="/index/start" />
          </Switch>
        </Layout>

      </Layout>
    );
  }
}

export default Index;